package com.tjc.eventbus.core;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;

/**
 * @Author: tjc
 * @description
 * @Date Created in 22:14 2022-01-12
 */
public class TMap<T> extends LinkedHashMap<String, Set<T>> {

    public T put(String key, T value) {
        Set<T> set = this.get(key);
        if (set == null) {
            set = new HashSet<>();
        }
        if(!set.contains(value)) {
            set.add(value);
        }
        this.put(key, set);
        return value;
    }

    public T remove(String key, T value) {
        Set<T> set = this.get(key);
        if (set == null) {
            set = new HashSet<>();
        }
        if(set.contains(value)) {
            set.remove(value);
        }
        this.put(key, set);
        return value;
    }
}
